//遍历
#include "family.h"
#include <queue>

//层序遍历
void FamilyTree::levelOrderTraversal() {
    if (root == nullptr) return;

    std::queue<FamilyMember*> q;
    q.push(root);

    while (!q.empty()) {
        FamilyMember* current = q.front();
        q.pop();

        std::cout << "姓名: " << current->name << ", 出生日期: " << current->birthDate << ", 联系信息: " << current->contactInfo << std::endl;

        for (auto child : current->children) {
            q.push(child);
        }
    }
}

// 先序遍历树并输出
void FamilyTree::preOrderTraversal(FamilyMember* node) {
    if (node == nullptr) return;

    std::cout << "姓名: " << node->name << ", 出生日期: " << node->birthDate << ", 联系信息: " << node->contactInfo << std::endl;

    for (auto child : node->children) {
        preOrderTraversal(child);
    }
}

// 后序遍历树并输出/
void FamilyTree::postOrderTraversal(FamilyMember* node) {
    if (node == nullptr) return;

    for (auto child : node->children) {
        postOrderTraversal(child);
    }

    std::cout << "姓名: " << node->name << ", 出生日期: " << node->birthDate << ", 联系信息: " << node->contactInfo << std::endl;
}

// 中序遍历树并输出 /
void FamilyTree::inOrderTraversal(FamilyMember* node) {
    if (node == nullptr) return;

    if (!node->children.empty()) {
        inOrderTraversal(node->children[0]);
    }

    std::cout << "姓名: " << node->name << ", 出生日期: " << node->birthDate << ", 联系信息: " << node->contactInfo << std::endl;

    for (size_t i = 1; i < node->children.size(); ++i) {
        inOrderTraversal(node->children[i]);
    }
}